package com.lagou;

import com.lagou.bean.ConsumerComponent;
import org.apache.dubbo.config.spring.context.annotation.EnableDubbo;
import org.apache.dubbo.rpc.RpcContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;

import java.io.IOException;
import java.util.Map;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;


public class AnnotationConsumerMain {
    public static void main(String[] args) throws IOException, InterruptedException {
        AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(ConsumerConfiguration.class);
        context.start();
        ConsumerComponent service = context.getBean(ConsumerComponent.class);
        System.out.println("开始连接zk==============");

        RpcContext.getContext().setAttachment("parm", "嘿嘿111111");


        String hello = service.sayHello("world", 100);


        System.out.println("result :" + hello);
       /* while (true) {
            try {

                String hello = service.sayHello("world", 100);
                System.out.println("result :" + hello);
            } catch (Exception e) {
                e.printStackTrace();
            }

        }*/






        MyTask myTask = new MyTask();

        //创建一个固定的线程池 5个
        ExecutorService es = Executors.newFixedThreadPool(10);

        //执行10次线程
        while (true){

            service.methodA();
            service.methodB();
            service.methodC();
            try {
                Thread.sleep(3);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }



    }


    public static class MyTask implements Runnable{

        @Override
        public void run() {
            System.err.println("当前线程执行的时间戳：" + System.currentTimeMillis()
                    + ",Thread ID:" + Thread.currentThread().getId());
        }

    }




    @Configuration
    @PropertySource("classpath:/dubbo-consumer.properties")
    //@EnableDubbo(scanBasePackages = "com.lagou.bean")
    @ComponentScan("com.lagou.bean")
    @EnableDubbo
    static class ConsumerConfiguration {

    }
}
